package com.example.rentalclearing.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;

// 结果类
@Data
@Schema(description = "结果类")
public class ClearingResult {

    @Schema(description = "核销总笔数")
    private int totalRecords;

    @Schema(description = "核销总本金")
    private BigDecimal totalPrincipal;

    @Schema(description = "核销总利息")
    private BigDecimal totalInterest;

    @Schema(description = "核销耗时（秒）")
    private long durationSeconds;

    public ClearingResult() {}

    public ClearingResult(int totalRecords, BigDecimal totalPrincipal, BigDecimal totalInterest, long durationSeconds) {
        this.totalRecords = totalRecords;
        this.totalPrincipal = totalPrincipal;
        this.totalInterest = totalInterest;
        this.durationSeconds = durationSeconds;
    }

    /**
     * 合并结果
     * @param other
     * @return
     */
    public ClearingResult merge(ClearingResult other) {
        this.totalRecords += other.totalRecords;
        this.totalPrincipal = this.totalPrincipal.add(other.totalPrincipal);
        this.totalInterest = this.totalInterest.add(other.totalInterest);
        return this;
    }

}
